package com.sweet.mealon.face.daily.lock.concurence.cyclicBarrier;

import lombok.AllArgsConstructor;

import java.util.Random;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.TimeUnit;

/**
 * faceDaily
 *
 * @Author: craizer.huang
 * @Date: 2021/5/1 14:23
 **/
@AllArgsConstructor
public class CyclicBarrierThread implements Runnable {
    private CyclicBarrier cyclicBarrier;
    public void run() {
        try {
            TimeUnit.SECONDS.sleep(5);
            System.out.println(String.format("%s arrive A",Thread.currentThread().getName()));
            cyclicBarrier.await();
            System.out.println(String.format("%s complete A",Thread.currentThread().getName()));


            TimeUnit.SECONDS.sleep(5);
            System.out.println(String.format("%s arrive B",Thread.currentThread().getName()));
            cyclicBarrier.await();
            System.out.println(String.format("%s complete B",Thread.currentThread().getName()));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
